#include <assert.h>
#include <string.h>

#include "fakenet.h"
#include "fakenet_interface.h"
#include "CaffCache/hash_table.h"
#include "uarch/mreq.h"
#include "uarch/sim.h"

extern Simulator Sim;

/********************
 * Bus_network Interface
 ********************/
Fakenet_interface::Fakenet_interface (Network *my_net, ModuleID moduleID)
    : Network_interface(my_net, moduleID, "FI_")
{
}

Fakenet_interface::~Fakenet_interface ()
{
}

void Fakenet_interface::tick ()
{
    Mreq *request;
    
    while ((request = read_input_port ()) != NULL)
    {
        ((Fakenet_interface *) my_net->get_interface(request->dest_mid.nodeID))->in_request_queue.push(request);
    }
}

void Fakenet_interface::tock ()
{
    Mreq *request;
    while (!in_request_queue.empty()) 
    {
        request = in_request_queue.front ();
        in_request_queue.pop ();

        assert (request->dest_mid.nodeID == moduleID.nodeID && "wrong destination?");
        //request->add_to_history(request, "fakenet");
        write_output_port (request, Global_Clock + 10);
    }
}
